package com.ziytek.web.citizen.export.excl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ziytek.web.citizen.constant.NumConstant;
import com.ziytek.web.citizen.enums.StepNameEnum;
import com.ziytek.web.citizen.model.bean.AddSettings;
import com.ziytek.web.citizen.pojo.basic.BasicStepSettings;
import com.ziytek.web.citizen.util.ChargeTypeUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xddf.usermodel.PresetColor;
import org.apache.poi.xddf.usermodel.XDDFColor;
import org.apache.poi.xddf.usermodel.XDDFSolidFillProperties;
import org.apache.poi.xddf.usermodel.chart.*;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTDLbls;
import org.openxmlformats.schemas.drawingml.x2006.chart.STDLblPos;

import java.util.Arrays;
import java.util.List;

/**
 * @className ChartUtils
 * @description: 描述
 * @jdkVersion: 1.8
 * @author: fhx
 * @date: 2024/7/2 9:53
 */
public class ChartUtils {
    private static XSSFChart createDrawingPatriarch(XSSFSheet sheet, ChartPosition chartPosition, String chartTitle) {
        //创建一个画布
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
        //前偏移量四个默认0
        XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, chartPosition.getCol1(), chartPosition.getRow1(), chartPosition.getCol2(), chartPosition.getRow2());
        //创建一个chart对象
        XSSFChart chart = drawing.createChart(anchor);
        //标题
        chart.setTitleText(chartTitle);
        //标题是否覆盖图表
        chart.setTitleOverlay(false);
        return chart;
    }

    public static ChartPosition chartPosition;
    public static int chartRowStart2 = 0;
    // 结束行
    public static int chartRowEnd2 = 32;

    public static XSSFWorkbook createLine(List<LineChartModel> lineCharts) {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("折线图");
        //-------------------------折线图--------------------------
        //List<LineChartModel> lineCharts = initLineChartTest();
        for (LineChartModel lineChart : lineCharts) {
            // 图表位置（左上角坐标，右下角坐标） 左上角坐标的（列，行），（右下角坐标）列，行,偏移量均为0
            chartPosition = new ChartPosition()
                    .setRow1(chartRowStart2)
                    .setCol1(0)
                    .setRow2(chartRowEnd2)
                    .setCol2(lineChart.getXAxisList().size() + 3);
            ChartUtils.createLineDouble(sheet, chartPosition, lineChart);
        }

        return workbook;
    }

    /**
     * 柱状图
     *
     * @param sheet         sheet
     * @param chartPosition chartPosition
     * @param pieChart      PieChartModel
     */
    public static void createBar(XSSFSheet sheet, ChartPosition chartPosition, PieChartModel pieChart) {
        String titleName = pieChart.getTitleName();
        List<String> titleList = pieChart.getTitleList();
        List<Integer> dataList = pieChart.getDataList();
        XSSFChart chart = createDrawingPatriarch(sheet, chartPosition, titleName);
        //分类轴标(X轴),标题位置
        XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
        //值(Y轴)轴,标题位置
        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
        //分类轴标数据
        XDDFDataSource<String> xData = XDDFDataSourcesFactory.fromArray(titleList.toArray(new String[]{}));
        XDDFNumericalDataSource<Integer> values = XDDFDataSourcesFactory.fromArray(dataList.toArray(new Integer[]{}));
        //bar：条形图
        XDDFBarChartData bar = (XDDFBarChartData) chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);
        leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
        //设置为可变颜色
        bar.setVaryColors(true);
        //条形图方向，纵向/横向：纵向
        bar.setBarDirection(BarDirection.COL);
        //图表加载数据，条形图1
        XDDFBarChartData.Series series1 = (XDDFBarChartData.Series) bar.addSeries(xData, values);
        //条形图例标题
        XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(PresetColor.BLUE_VIOLET));
        //条形图，填充颜色
        series1.setFillProperties(fill);
        //绘制
        chart.plot(bar);
    }

    /**
     * 创建饼图
     *
     * @param sheet 图表
     * @see PieChartModel  饼图数据的封装
     * @see ChartPosition 饼图的坐标位置
     */
    public static void createPie(XSSFSheet sheet, ChartPosition chartPosition, PieChartModel pieChart) {
        String titleName = pieChart.getTitleName();
        List<String> titleList = pieChart.getTitleList();
        List<Integer> dataList = pieChart.getDataList();
        XSSFChart chart = createDrawingPatriarch(sheet, chartPosition, titleName);
        //图例位置
        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.BOTTOM);
        //分类轴标数据
        XDDFDataSource<String> countries = XDDFDataSourcesFactory.fromArray(titleList.toArray(new String[]{}));
        XDDFNumericalDataSource<Integer> values = XDDFDataSourcesFactory.fromArray(dataList.toArray(new Integer[]{}));
        XDDFChartData data = chart.createData(ChartTypes.PIE, null, null);
        //设置为可变颜色
        data.setVaryColors(true);
        //图表加载数据
        data.addSeries(countries, values);
        //绘制
        chart.plot(data);
        CTDLbls ctdLbls = chart.getCTChart().getPlotArea().getPieChartArray(0).getSerArray(0).addNewDLbls();
        ctdLbls.addNewShowVal().setVal(false);
        ctdLbls.addNewShowLegendKey().setVal(false);
        //类别名称
        ctdLbls.addNewShowCatName().setVal(false);
        //百分比
        ctdLbls.addNewShowSerName().setVal(false);
        ctdLbls.addNewShowPercent().setVal(true);
        //引导线
        ctdLbls.addNewShowLeaderLines().setVal(false);
        //分隔符为分行符
        ctdLbls.setSeparator("\n");
        //数据标签内
        ctdLbls.addNewDLblPos().setVal(STDLblPos.Enum.forString("inEnd"));
    }

    /**
     * 创建折线图
     *
     * @param sheet 图表
     * @see LineChartModel  饼图数据的封装
     * @see ChartPosition 饼图的坐标位置
     */
    public static void createLine(XSSFSheet sheet, ChartPosition chartPosition, LineChartModel lineChart) {
        List<Object> xAxisList = lineChart.getXAxisList();
        List<String> chartTitleList = lineChart.getTitleList();
        List<List<Integer>> chartDataList = lineChart.getDataList();
        String chartTitle = lineChart.getChartTitle();
        XSSFChart chart = createDrawingPatriarch(sheet, chartPosition, chartTitle);
        //图例位置
        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.TOP);
        //分类轴标(X轴),标题位置
        XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
        //值(Y轴)轴,标题位置
        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
        //LINE：折线图
        XDDFLineChartData data = (XDDFLineChartData) chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
        XDDFCategoryDataSource countries = XDDFDataSourcesFactory.fromArray(Arrays.copyOf(xAxisList.toArray(), xAxisList.toArray().length, String[].class));
        for (int i = 0; i < chartDataList.size(); i++) {
            List<Integer> floats = chartDataList.get(i);
            XDDFNumericalDataSource<Integer> dataSource = XDDFDataSourcesFactory.fromArray(floats.toArray(new Integer[]{}));
            //图表加载数据，折线
            XDDFLineChartData.Series series = (XDDFLineChartData.Series) data.addSeries(countries, dataSource);
            series.setTitle(chartTitleList.get(i), null);
            //直线
            series.setSmooth(false);
            //设置标记大小
            series.setMarkerSize((short) 2);
            //添加标签数据，折线图中拐点值展示
            series.setShowLeaderLines(true);
            chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(i).getDLbls().addNewDLblPos().setVal(org.openxmlformats.schemas.drawingml.x2006.chart.STDLblPos.CTR);
            chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(i).getDLbls().addNewShowVal().setVal(true);
            chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(i).getDLbls().addNewShowLegendKey().setVal(false);
            chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(i).getDLbls().addNewShowCatName().setVal(false);
            chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(i).getDLbls().addNewShowSerName().setVal(false);
        }
        //绘制
        chart.plot(data);
        if (chartDataList.size() == 1) {
            chart.getCTChart().getPlotArea().getLineChartArray(0).addNewVaryColors().setVal(false);
        }
    }

    /**
     * 创建折线图 双Y坐标
     *
     * @param sheet 图表
     * @see LineChartModel  饼图数据的封装
     * @see ChartPosition 饼图的坐标位置
     */
    public static void createLineDouble(XSSFSheet sheet, ChartPosition chartPosition, LineChartModel lineChart) {

        List<Object> xAxisList = lineChart.getXAxisList();
        List<String> chartTitleList = lineChart.getTitleList();
        List<List<Integer>> chartDataList = lineChart.getDataList();
        String chartTitle = lineChart.getChartTitle();
        XSSFChart chart = createDrawingPatriarch(sheet, chartPosition, chartTitle);

        //图例位置
        XDDFChartLegend legend = chart.getOrAddLegend();
        legend.setPosition(LegendPosition.TOP);
        //legend.setPosition(LegendPosition.TOP_RIGHT);

        //分类轴标(X轴),标题位置
        XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
        bottomAxis.setCrosses(AxisCrosses.MIN);

        //值(Y轴)轴,标题位置
        XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
        leftAxis.setCrosses(AxisCrosses.MIN);
        leftAxis.crossAxis(bottomAxis);
        // 设置轴标题
        leftAxis.setTitle("电压(mV)");

        XDDFValueAxis rightAxis = chart.createValueAxis(AxisPosition.RIGHT);
        rightAxis.setTitle("电流(mA)");

        rightAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
        rightAxis.setCrosses(AxisCrosses.MAX);
        rightAxis.crossAxis(bottomAxis);


        // 设置左边 Y轴参数
        leftAxis.setMaximum(5000D);
        leftAxis.setMinimum(00D);
        leftAxis.setMajorUnit(500D);

        // 设置右边 Y轴参数
        rightAxis.setMaximum(6000D);
        rightAxis.setMinimum(-6000D);
        rightAxis.setMajorUnit(1200D);

        // 第一个点从0开始
        //bottomAxis.crossAxis(rightAxis);

        //LINE：折线图
        XDDFLineChartData data = (XDDFLineChartData) chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
        XDDFLineChartData rightData = (XDDFLineChartData) chart.createData(ChartTypes.LINE, bottomAxis, rightAxis);
        XDDFCategoryDataSource countries = XDDFDataSourcesFactory.fromArray(Arrays.copyOf(xAxisList.toArray(), xAxisList.toArray().length, String[].class));

        List<Integer> floats = chartDataList.get(0);
        List<Integer> rightFloats = chartDataList.get(1);

        XDDFNumericalDataSource<Integer> dataSourceOne = XDDFDataSourcesFactory.fromArray(floats.toArray(new Integer[]{}));
        XDDFNumericalDataSource<Integer> dataSourceTwo = XDDFDataSourcesFactory.fromArray(rightFloats.toArray(new Integer[]{}));
        //图表加载数据，折线
        XDDFLineChartData.Series series = (XDDFLineChartData.Series) data.addSeries(countries, dataSourceOne);
        XDDFLineChartData.Series seriesTwo = (XDDFLineChartData.Series) rightData.addSeries(countries, dataSourceTwo);
        series.setTitle(chartTitleList.get(0), null);
        seriesTwo.setTitle(chartTitleList.get(1), null);

        //直线
        series.setSmooth(true);
        seriesTwo.setSmooth(true);
        //设置标记大小
        series.setMarkerSize((short) 2);
        seriesTwo.setMarkerSize((short) 2);
        // 折线点形状
        series.setMarkerStyle(MarkerStyle.NONE);
        seriesTwo.setMarkerStyle(MarkerStyle.NONE);

        // 颜色

        //添加标签数据,折线图中拐点值展示
        series.setShowLeaderLines(false);
        seriesTwo.setShowLeaderLines(false);

        chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewDLblPos().setVal(STDLblPos.CTR);
        //添加标签数据,折线图中拐点值展示false-不显示 true-显示
        chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewShowVal().setVal(false);
        chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewShowLegendKey().setVal(false);
        chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewShowCatName().setVal(false);
        chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewShowSerName().setVal(false);

        chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getDLbls().addNewDLblPos().setVal(STDLblPos.CTR);
        //添加标签数据,折线图中拐点值展示false-不显示 true-显示
        chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getDLbls().addNewShowVal().setVal(false);
        chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getDLbls().addNewShowLegendKey().setVal(false);
        chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getDLbls().addNewShowCatName().setVal(false);
        chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getDLbls().addNewShowSerName().setVal(false);

        //绘制
        chart.plot(data);
        chart.plot(rightData);
        if (chartDataList.size() == 1) {
            chart.getCTChart().getPlotArea().getLineChartArray(0).addNewVaryColors().setVal(false);
        }
    }


    /**
     * 创建列表
     */
    public static void createTable(int rowNum, XSSFWorkbook wb, XSSFSheet sheet) {
        // 样式
        XSSFCellStyle titleStyle = createTitleCellStyle(wb);
        XSSFCellStyle contentStyle = createContentCellStyle(wb);
        // 创建第一页的第一行，索引从0开始
        XSSFRow row = sheet.createRow(rowNum);
        row.setHeight((short) 500);
        XSSFCell cell0 = row.createCell(0);
        cell0.setCellValue("动态列表");
        cell0.setCellStyle(tableNameCellStyle(wb));
        // 合并单元格，参数依次为起始行，结束行，起始列，结束列 （索引0开始）
        sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 2));

        XSSFRow row1 = sheet.createRow(rowNum + 1);
        XSSFRow row2 = sheet.createRow(rowNum + 2);
        row1.setHeight((short) 600);
        row2.setHeight((short) 600);

        String title0 = "序号";
        XSSFCell cell = row1.createCell(0);
        cell.setCellValue(title0);
        // 合并单元格，参数依次为起始行，结束行，起始列，结束列 （索引0开始）
        CellRangeAddress region = new CellRangeAddress(rowNum + 1, rowNum + 2, 0, 0);
        sheet.addMergedRegion(region);
        // 合并之后为合并的单元格设置样式
        setRegionStyle(sheet, region, titleStyle);

        String title = "城市";
        XSSFCell c00 = row1.createCell(1);
        c00.setCellValue(title);
        // 合并单元格，参数依次为起始行，结束行，起始列，结束列 （索引0开始）
        CellRangeAddress cellRangeAddress = new CellRangeAddress(rowNum + 1, rowNum + 2, 1, 1);
        sheet.addMergedRegion(cellRangeAddress);
        setRegionStyle(sheet, cellRangeAddress, titleStyle);

        String[] years = {"21年", "22年", "23年"};
        int startCellIndex = 2;
        int endCellIndex = 4;
        // 动态年份
        for (int i = 0; i < years.length; i++) {
            XSSFCell cell1 = row1.createCell(startCellIndex);
            cell1.setCellValue(years[i]);
            CellRangeAddress cellAddresses = new CellRangeAddress(rowNum + 1, rowNum + 1, startCellIndex, endCellIndex);
            sheet.addMergedRegion(cellAddresses);
            setRegionStyle(sheet, cellAddresses, titleStyle);
            XSSFCell cell11 = row2.createCell(startCellIndex++);
            cell11.setCellValue("动态列1");
            cell11.setCellStyle(titleStyle);
            XSSFCell cell2 = row2.createCell(startCellIndex++);
            cell2.setCellValue("动态列2");
            cell2.setCellStyle(titleStyle);
            XSSFCell cell3 = row2.createCell(startCellIndex++);
            cell3.setCellValue("动态列3");
            cell3.setCellStyle(titleStyle);
            endCellIndex += 3;
        }

        rowNum += 3;
        for (int j = 0; j < 10; j++) {
            int k = j + 1;
            XSSFRow tempRow = sheet.createRow(rowNum);
            rowNum++;
            // 序号
            XSSFCell cell11 = tempRow.createCell(0);
            cell11.setCellValue(k);
            cell11.setCellStyle(contentStyle);
            // 城市
            XSSFCell cell2 = tempRow.createCell(1);
            cell2.setCellValue("城市" + k);
            cell2.setCellStyle(contentStyle);
            int columnIndex = 2;
            int k1 = 1;
            for (int i = 0; i < years.length; i++) {
                XSSFCell cell3 = tempRow.createCell(columnIndex++);
                cell3.setCellValue("测试" + k1++);
                cell3.setCellStyle(contentStyle);
                XSSFCell cell4 = tempRow.createCell(columnIndex++);
                cell4.setCellValue("测试" + k1++);
                cell4.setCellStyle(contentStyle);
                XSSFCell cell5 = tempRow.createCell(columnIndex++);
                cell5.setCellValue("测试" + k1++);
                cell5.setCellStyle(contentStyle);
            }
        }
    }

    public static void createTableMsg(BasicStepSettings basicStepSetting, int rowNum, XSSFWorkbook wb, XSSFSheet sheet, List<AddSettings> settings, int maxChargeLimitCurrent) {
        if (CollectionUtils.isEmpty(settings)) {
            return;
        }


        // 样式
//        XSSFCellStyle titleStyle = createTitleCellStyle(wb);
//        XSSFCellStyle contentStyle = createContentCellStyle(wb);
        // 创建第一页的第一行，索引从0开始
        XSSFRow row = sheet.createRow(rowNum);
        row.setHeight((short) 500);
        XSSFCell cell0 = row.createCell(0);
        StringBuilder msg = new StringBuilder("工步设定值 \r\n");

        boolean isLoop = false;
        int loops = NumConstant.INT_LT_ZERO;
        int orderEnd = NumConstant.INT_LT_ZERO;
        int orderBegin = NumConstant.INT_LT_ZERO;
        AddSettings begin = null;
        AddSettings end = null;
        if (basicStepSetting != null && basicStepSetting.getIsLoop() >= NumConstant.INT_ONE) {
            isLoop = true;
            loops = basicStepSetting.getIsLoop();
            orderBegin = basicStepSetting.getLoopOrderBegin();
            orderEnd = basicStepSetting.getLoopOrderEnd();
        }

        int index = 0;
        for (AddSettings setting : settings) {
            index += 1;
            msg.append(ChargeTypeUtil.getChargeTypeName(index, setting, maxChargeLimitCurrent));

            if (isLoop && setting.getSettingOrder() == orderBegin) {
                begin = setting;
            }
            if (isLoop && setting.getSettingOrder() == orderEnd) {
                end = setting;
            }
            if (isLoop && begin != null && end != null) {
                index += 1;
                msg.append(index).append(".循环").append(loops).append("次 ")
                        .append(StepNameEnum.STEP_CC.getMsg(begin.getSetType())).append("-")
                        .append(StepNameEnum.STEP_CC.getMsg(end.getSetType())).append(" \r\n");
                begin = null;
                end = null;
            }
        }

        msg.append(index + 1).append(".结束 \r\n");

        cell0.setCellValue(msg.toString());
        cell0.setCellStyle(tableNameCellStyle(wb));
        // 合并单元格，参数依次为起始行，结束行，起始列，结束列 （索引0开始）
        sheet.addMergedRegion(new CellRangeAddress(0, 15, 0, 10));
    }

    /**
     * 为合并的单元格设置样式（可根据需要自行调整）
     */
    @SuppressWarnings("deprecation")
    public static void setRegionStyle(XSSFSheet sheet, CellRangeAddress region, XSSFCellStyle cs) {
        for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
            XSSFRow row = sheet.getRow(i);
            if (null == row) {
                row = sheet.createRow(i);
            }
            for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
                XSSFCell cell = row.getCell(j);
                if (null == cell) {
                    cell = row.createCell(j);
                }
                cell.setCellStyle(cs);
            }
        }
    }

    /**
     * 列表名称样式
     *
     * @param wb wb
     * @return XSSFCellStyle
     */
    public static XSSFCellStyle tableNameCellStyle(XSSFWorkbook wb) {
        XSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setWrapText(true);
        //垂直对齐
//        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.TOP);
        // 创建字体样式
        XSSFFont headerFont1 = wb.createFont();
        //字体加粗
        headerFont1.setBold(true);
        headerFont1.setBold(false);
        // 设置字体类型
        headerFont1.setFontName("黑体");
        headerFont1.setFontName("宋体");
        // 设置字体颜色 red
//        headerFont1.setColor((short) 10);
        // 设置字体大小
        headerFont1.setFontHeightInPoints((short) 13);
        // 为标题样式设置字体样式
        cellStyle.setFont(headerFont1);
        return cellStyle;
    }

    /**
     * 创建标题样式
     *
     * @param wb
     * @return
     */
    private static XSSFCellStyle createTitleCellStyle(XSSFWorkbook wb) {
        XSSFCellStyle cellStyle = wb.createCellStyle();
        //水平居中
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        //垂直对齐
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        //背景颜色
        cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        cellStyle.setBottomBorderColor(IndexedColors.BLACK.index);
        //下边框
        cellStyle.setBorderBottom(BorderStyle.THIN);
        //左边框
        cellStyle.setBorderLeft(BorderStyle.THIN);
        //右边框
        cellStyle.setBorderRight(BorderStyle.THIN);
        //上边框
        cellStyle.setBorderTop(BorderStyle.THIN);

        // 创建字体样式
        XSSFFont headerFont1 = wb.createFont();
        //字体加粗
//        headerFont1.setBold(true);
        // 设置字体类型
        headerFont1.setFontName("黑体");
        // 设置字体大小
        headerFont1.setFontHeightInPoints((short) 12);
        // 为标题样式设置字体样式
        cellStyle.setFont(headerFont1);
        return cellStyle;
    }

    /**
     * 创建内容样式
     *
     * @param wb wb
     * @return XSSFCellStyle
     */
    private static XSSFCellStyle createContentCellStyle(XSSFWorkbook wb) {
        XSSFCellStyle cellStyle = wb.createCellStyle();
        // 垂直居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        // 水平居中
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        // 设置自动换行
        cellStyle.setWrapText(true);
        //下边框
        cellStyle.setBorderBottom(BorderStyle.THIN);
        //左边框
        cellStyle.setBorderLeft(BorderStyle.THIN);
        //右边框
        cellStyle.setBorderRight(BorderStyle.THIN);
        //上边框
        cellStyle.setBorderTop(BorderStyle.THIN);

        // 生成12号字体
        XSSFFont font = wb.createFont();
        font.setColor((short) 8);
        font.setFontHeightInPoints((short) 12);
        cellStyle.setFont(font);

        return cellStyle;
    }

}